//
//  ToneMapperView.m
//  ToneMapper
//
//  Created by Andrey on 03/02/2009.
//  Copyright 2009 Karma Software. All rights reserved.
//

#import <QuartzCore/QuartzCore.h>
#import "ToneMapperView.h"

@implementation ToneMapperView

- (id)initWithFrame:(NSRect)frame 
{
    self = [super initWithFrame:frame];

    if (self) 
	{
		
    }
	
    return self;
}

- (BOOL)acceptsFirstResponder
{
	return YES;
}

- (void)mouseDown:(NSEvent*)theEvent
{
	BOOL keepOn = YES;
    BOOL isInside = YES;
    NSPoint mouseLocation;
	
    while (keepOn) 
	{
        theEvent = [[self window] 
					nextEventMatchingMask: NSLeftMouseUpMask | NSLeftMouseDraggedMask];
        mouseLocation = 
		[self convertPoint:[theEvent locationInWindow] fromView:nil];
        isInside = 
		[self mouse:mouseLocation inRect:[self bounds]];
		
        switch ([theEvent type]) 
		{
            case NSLeftMouseDragged:
				[controller trackMouseDragging:mouseLocation];
				break;
				
            case NSLeftMouseUp:
				keepOn = NO;
				break;
				
            default:
				break;
        }
    };
	
    return;
}

- (void)drawRect:(NSRect)rect 
{
	if (controller.displayBuffer != nil)
	{
		NSRect rectToDrawIn = 
		NSMakeRect(0, 0, controller.displayBuffer.width, controller.displayBuffer.height);
		
		[[controller.displayBuffer bitmap] drawInRect:rectToDrawIn];
	}
}

- (void) dealloc
{
	[super dealloc];
}
@end